
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import jxl.Sheet;
import jxl.Workbook;
import thesis.haipv.qa.model.Answer;
import thesis.haipv.qa.model.Feedback;
import thesis.haipv.qa.model.Question;
import thesis.haipv.qa.model.UserProfile;
import thesis.haipv.qa.persistence.AnswerDAO;
import thesis.haipv.qa.persistence.FeedbackDAO;
import thesis.haipv.qa.persistence.QuestionDAO;
import thesis.haipv.qa.persistence.UserProfileDAO;

/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
/**
 *
 * @author PHANHAI
 */
public class Test {
static String path = "F:\\dataset.xls";
    public static void mainZZZ(String[] args) {
        long l1[] = new long[20];
        long l3[] = new long[20];
        long l2[] = new long[40];

        for (int i = 0; i < 20; ++i) {
            l1[i] = 20100 + i;
            l3[i] = 20300 + i;
        }
        for (int i = 0; i < 40; ++i) {
            l2[i] = 20200 + i;
        }

        int c1 = 0;
        int z1 = 0;
        int c3 = 0;
        int z3 = 0;
        int c21 = 0;
        int c23 = 39;
        int z21 = 0;
        int z23 = 0;

        for (int i = 1; i <= 1000; i++) {
            if (i % 2 == 1) {
                if (z1 < 300) {
                    System.out.println("" + l1[c1++]);
                    z1++;
                    if (c1 >= 20) {
                        c1 = 0;
                    }
                } else {
                    if (z21 < 200) {
                        System.out.println("" + l2[c21++]);
                        z21++;
                        if(c21 >= 40) {
                            c21 = 0;
                        }
                    }
                }
            } else {
                if (z3 < 300) {
                    System.out.println("" + l3[c3++]);
                    z3++;
                    if (c3 >= 20) {
                        c3 = 0;
                    }
                } else {
                    if (z23 < 200) {
                        System.out.println("" + l2[c23--]);
                        z23++;
                        if(c23 < 0) {
                            c23 = 39;
                        }
                    }
                }
            }
            
        }
        System.out.println("SUM: " + z23);
    }
//    

    private static void createUser() {
        long currentTime = System.currentTimeMillis();
        int N = 1000;
        UserProfileDAO dao = new UserProfileDAO();
        for (int i = 1; i <= N; ++i) {
            String username = "pos" + i;
            String fullname = "Thông thái " + i;
            String password = "" + i;
           // UserProfile up = new UserProfile(username, password, fullname, currentTime);
           // dao.createUserProfile(up);
        }
    }

    private static void feedback() {
        FeedbackDAO dao = new FeedbackDAO();
        Random rnd = new Random();
        System.out.println("Running.........");
        for (int i = 1; i <= 24; i += 3) {
            long currentTime = System.currentTimeMillis();
            String username = "pos" + i;
            float trust = (float) (8 + Math.abs(rnd.nextInt() % (10 - 8 + 1))) / 10.0f;
            //  dao.createFeedback(trust, username, 3, currentTime);
            try {
                Thread.sleep(20000);
            } catch (InterruptedException ex) {
                Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        System.out.println("Finish!");
    }
    public static void mainzzz(String[] args) {
        try {
           
            File file = new File(path);
            Workbook wrk1 = Workbook.getWorkbook(file);
            Sheet sh = wrk1.getSheet(3);
            int numUsers = 130;
            int numQuestion = 500;
            int numAns = 1000;
            UserProfileDAO udao = new UserProfileDAO();
            //QuestionDAO qdao = new QuestionDAO();
 //           AnswerDAO adao = new AnswerDAO();
            System.out.println("Running...........");
//            for(int i = 1; i <= numUsers; ++i) {
//                 String content = sh.getCell(0, i).getContents().trim();
//                udao.createUserProfile(new UserProfile(content, "admin", ""));
//            }
//            for(int i = 1; i <= numQuestion; ++i) {
//                String content = sh.getCell(2, i).getContents().trim();
//                String asker = sh.getCell(1, i).getContents().trim();
//                long time = Long.parseLong(sh.getCell(3, i).getContents().trim());
//                int id = Integer.parseInt(sh.getCell(0, i).getContents().trim());
//                qdao.createQuestion(id, content, asker, time);
//            }
//            for(int i = 1; i <= numAns; ++i) {
//                String content = sh.getCell(4, i).getContents().trim();
//                String asker = sh.getCell(2, i).getContents().trim();
//                long time = Long.parseLong(sh.getCell(5, i).getContents().trim());
//                int id = Integer.parseInt(sh.getCell(0, i).getContents().trim());
//                int qid = Integer.parseInt(sh.getCell(1, i).getContents().trim());
//                adao.createAnswer(id, content, qid, asker, time);
//            }
            int uuu = 10001;
            for(int i = 1; i <= numAns; ++i) {
                float trust = Float.parseFloat(sh.getCell(3, i).getContents().trim());
                String asker = sh.getCell(2, i).getContents().trim();
                long time = Long.parseLong(sh.getCell(5, i).getContents().trim());
                int id = Integer.parseInt(sh.getCell(0, i).getContents().trim());
               // int qid = Integer.parseInt(sh.getCell(1, i).getContents().trim());
                //udao.postFeedback(""+uuu, asker, id, trust, time);
                if(i %2 == 0) {
                    uuu++;
                }
            }
            System.out.println("Finish!");
        } catch (Exception e) {
        }
    }
}
